#pragma once


#include "Types.h"
#include "eventman\IrrEventManager.h"
#include "Singleton.h"
#include "Container.h"
#include "CameraControl.h"
#include "HUDControl.h"
#include <map>
#include "ObjectTypesContainer.h"
#include "CollisionDispatcher.h"

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

using namespace IrrPhysx;

class CCameraControl;
class CShip;

enum E_STATE {
	Running,
	Paused
};

class CGameManager : public TSingleton<CGameManager>, public TRefCount<CGameManager> {
public:
	CGameManager(void);
	~CGameManager(void);

	// main loop handler functions


	// utility functions	
	void addObject(CSceneObject *);
	CSceneObject * getObject(s32 id);

	void removeObject(s32 id);
	void removeObject(CSceneObject *);
	
	OBJINTMAP getObjects(void)					{ return this->mObjectList; }

	E_GAMEOBJECT_TYPE getType()				{ return E_GAMEOBJECT_TYPE::Engine; }
	
	OBJSTRMAP getShipTypes(void)			{ return CObjectTypesContainer::Ships; }
	OBJSTRMAP getWeaponTypes(void)			{ return CObjectTypesContainer::Weapons; }
	OBJSTRMAP getProjectileTypes(void)		{ return CObjectTypesContainer::Projectiles; }

	

	E_STATE getState(void)					{ return this->mState; }
	void    setState(E_STATE value)			{ this->mState = value; }

	TContainer<CSceneObject*> getSelection(){ return this->mSelectionList; }

	void go(void);
	void pause(void);
	void unpause(void);

	DECLARE_GET_MEMBER(ISceneManager*, SceneManager)
	DECLARE_GET_MEMBER(IGUIEnvironment*, GuiManager)
	DECLARE_GET_MEMBER(CCameraControl*, CameraControl)
	DECLARE_GET_MEMBER(IEventManager*, EventManager)
	DECLARE_GET_MEMBER(IrrlichtDevice*, Device)
	DECLARE_GET_MEMBER(IPhysxManager*, PhysxManager)
	DECLARE_GET_MEMBER(IVideoDriver*, VideoDriver)
	DECLARE_GET_MEMBER(CCollisionDispatcher*, CollisionDispatcher)
private:
	E_STATE mState;

	// private functions
	void prepareDevice(E_DRIVER_TYPE deviceType, dimension2d<s32> dimensions, u32 depth, bool fullscreen, bool stencil, bool vsync);

	void MainLoop(void);
	void handleCamera(void);

	CHUDControl *mHudControl;

	OBJINTMAP mObjectList;
	TContainer<CSceneObject*> mSelectionList;
};
#ifdef _DEBUG
void TestLoad(CGameManager *engine);
void TestUpdate(CGameManager *engine, f32 frameDelta);
#endif
